<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="Token信息"
    width="550px"
    @close="emits('closeDialog')"
  >
    <el-form ref="dialogFormRef" :model="dialogForm" :rules="rules" :label-width="formLabelWidth">
      <el-form-item label="币种ID"  prop="coin_id">
        <el-input v-model="dialogForm.coin_id" />
      </el-form-item>
      <el-form-item
        label="Token名称"
       
        prop="token_name"
      >
        <el-input v-model="dialogForm.token_name" />
      </el-form-item>
      <el-form-item label="中文名称" >
        <el-input v-model="dialogForm.cn_name" />
      </el-form-item>
      <el-form-item label="英文名称" >
        <el-input v-model="dialogForm.en_name" />
      </el-form-item>
      <el-form-item
        label="主链名称"
        
        prop="chain_name"
      >
        <el-input v-model="dialogForm.chain_name" />
      </el-form-item>
      <el-form-item label="主链别名" >
        <el-input v-model="dialogForm.chain_alias" />
      </el-form-item>
      <el-form-item label="区块浏览器交易查询url" >
        <el-input v-model="dialogForm.chain_url" />
      </el-form-item>
      <div class="flx-center">
        <el-form-item label="是否启用" >
          <el-switch v-model="dialogForm.is_active" />
        </el-form-item>
        <el-form-item label="是否Memo/Tag类币种" >
          <el-switch v-model="dialogForm.is_memo" />
        </el-form-item>
      </div>
      <div class="flx-center">
        <el-form-item label="是否允许充值" >
          <el-switch v-model="dialogForm.is_deposit" />
        </el-form-item>
        <el-form-item label="是否允许提现" >
          <el-switch v-model="dialogForm.is_withdraw" />
        </el-form-item>
      </div>
      <el-form-item label="提现费用" >
        <el-input v-model="dialogForm.min_fee" />
      </el-form-item>
      <el-form-item label="最小充值数量" >
        <el-input v-model="dialogForm.min_deposit" />
      </el-form-item>
      <el-form-item label="最小提现数量" >
        <el-input v-model="dialogForm.min_withdraw" />
      </el-form-item>
      <el-form-item label="最大提现数量" >
        <el-input v-model="dialogForm.max_withdraw" />
      </el-form-item>
      <el-form-item label="确认数" >
        <el-input v-model="dialogForm.confirmations" />
      </el-form-item>
      <el-form-item label="合约地址" >
        <el-input v-model="dialogForm.contract" />
      </el-form-item>
      <el-form-item label="合约精度" >
        <el-input v-model="dialogForm.contract_precision" />
      </el-form-item>
      <el-form-item label="入账地址" >
        <el-input v-model="dialogForm.deposit_address" />
      </el-form-item>

      <el-form-item label="id" style="display: none">
        <el-input v-model="dialogForm.token_id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      token_id: "",
      coin_id: "",
      token_name: "",
      cn_name: "",
      en_name: "",
      chain_name: "",
      chain_alias: "",
      chain_url: "",
      is_active: false,
      is_memo: false,
      is_deposit: false,
      is_withdraw: false,
      min_fee: "",
      min_deposit: "",
      min_withdraw: "",
      max_withdraw: "",
      confirmations: "",
      contract: "",
      contract_precision: "",
      deposit_address: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "170px";
// 校验
const rules = {
  token_name: [{ required: true, message: "请输入主链名称", trigger: "blur" }],
  chain_name: [{ required: true, message: "请输入Token名称", trigger: "blur" }],
  coin_id: [{ required: true, message: "请输入币种ID", trigger: "blur" }],
};
// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        const param = Object.assign({}, dialogForm);
        param.is_deposit = param.is_deposit ? 1 : 0;
        param.is_withdraw = param.is_withdraw ? 1 : 0;
        emits("submitForm", param);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
